package com.gxa.ehome.controller;


import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserService;
import com.gxa.ehome.util.MapUtil;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//类中和方法都制定了method,那么对于register方法 两种都有效
//建议不再类中声明method
//


@Controller
@RequestMapping(value = "/sysUser3"/*,method =RequestMethod.GET*/)
@Api(value = "描述restful风格的控制器",tags = "restfulController")
public class RestfulController {

    //查询全部的用户信息
        @GetMapping
        @ApiOperation(value = "查询全部用户信息",notes ="使用restful风格中查询全部的槽子哦方式",tags = "getAll"
        ,response = List.class,httpMethod = "GET")
    public List<SysUser> getAll(){
            System.out.println("GET/ehome/sysUser3");
            return null;
        }
        @GetMapping("/{id}")
        @ApiOperation(value = "通过id获取SysUser对象的方法",notes = "getById"
        ,response = SysUser.class,httpMethod = "GET")
        @ApiImplicitParam(value = "用户id",required = true
        ,paramType ="Integer",example = "1")
        public SysUser getById(@PathVariable("id") Integer id ){
            System.out.println("GET/ehome/sysUser3/1");
            return null;
        }
    //分页查询
    @GetMapping("/page/{page}/limit/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",required = true,
            paramType = "Integer"), @ApiImplicitParam(name = "limit",required = true,
            paramType = "Integer")
    })
    public SysUser getByPage(@PathVariable("limit") Integer limit,@PathVariable("page") Integer page ){
        System.out.println("GET/ehome/sysUser3/page/1/limit/10");
        System.out.println("page"+page);
        System.out.println("limit:"+limit );
        return null;
    }
    @PostMapping
    public Boolean reg(@RequestBody @ApiParam(name = "SysUser",required = true,type = "SysUser") SysUser sysUser){
        System.out.println("POST/ehome/sysUser3");
        System.out.println("jobNumber"+sysUser.getJobNumber());
        return false;
    }
    //1,注入前端获取数据注入到sysUser对象上
    //2,前端获取注入到map上
//    @PostMapping
//    public Boolean reg2(@RequestBody Map<String,Object> objectMap){
//        System.out.println("POST/ehome/sysUser3");
//        System.out.println("jobNumber"+objectMap.get("JobNumber"));
//        return false;


    //修改sysUser对象信息
    @PutMapping ("/*/id/{id}*/")
    public void edit(@RequestBody SysUser sysUser){
        System.out.println("PUT/ehome/sysUser3");
        System.out.println("jobNumber"+sysUser.getJobNumber());
        System.out.println("id"+sysUser.getId());

        return ;
    }

    //如何与前端做好约定
    @DeleteMapping("/id/{id}")
    public  void delete(@PathVariable("id") Integer id){
        System.out.println("DELETE/ehome/sysUser3");
        System.out.println("id"+id);

    }
    @DeleteMapping
    public  void delete() {
        System.out.println("DELETE/ehome/sysUser3");
        System.out.println("---------");


    }


    }
